package cn.chilemou;

import com.rabbitmq.client.Address;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author LiXingShuai
 * @className Util
 * @description: TODO
 * @date 2023年04月13日
 * @version: 1.0
 */
public class Util {

    private static final String EXCHANGE_NAME ="exchange_demo";
    private static final String ROUTING_KEY ="routingKey_demo";
    private static final String QUEUE_MAME ="queue_demo";

    private static final String IP_ADDRESS ="47.94.171.202";

    private static final int PORT = 5672;

    private static final String USERNAME = "root";
    private static final String PWD = "root";

    private static final String VHOST_NAME = "host1";
    public static Connection getProductorConnection() {
           ConnectionFactory connectionFactory = new ConnectionFactory();
           connectionFactory.setHost(IP_ADDRESS);
           connectionFactory.setPort(PORT);
           connectionFactory.setUsername(USERNAME);
           connectionFactory.setPassword(PWD);
           connectionFactory.setVirtualHost(VHOST_NAME);
        try {
            return connectionFactory.newConnection();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (TimeoutException e) {
            throw new RuntimeException(e);
        }
    }
    public static Connection getConsumerConnection()  {
        Address[] addresses = new Address[]{new Address(IP_ADDRESS,PORT)};

        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setUsername(USERNAME);
        connectionFactory.setPassword(PWD);
        connectionFactory.setVirtualHost(VHOST_NAME);
        try {
            return connectionFactory.newConnection(addresses);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (TimeoutException e) {
            throw new RuntimeException(e);
        }
    }


}
